#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

void display(vector<int>, ostream& = cout);
void swap(int&, int&);
void bubble_sort(vector<int>& vec, ofstream * = 0);
// ofstream ofil("text_out1");

int main()
{
    int ia[8] = {85, 16, 454, 127, 45, 210, 54, 124};
    vector<int> vec(ia, ia + 8);

    cout << "vector before sort: ";
    display(vec);

    bubble_sort(vec);

    cout << "vector after sort: ";
    display(vec);

    return 0;
}

void display(vector<int> vec, ostream& os)
{
    for (int ix = 0; ix < (int)vec.size(); ix++)
        os << vec[ix] << " ";
    os << endl;
}

void swap(int & val1, int & val2)
{
    int temp = val1;
    val1 = val2;
    val2 = temp;
}


void bubble_sort(vector<int> & vec, ofstream * ofil)
{
    for (int ix = 0; ix < (int)vec.size(); ix++)
        for (int jx = ix + 1; jx < (int)vec.size(); ++jx)
            if (vec[ix] > vec[jx])
            {
                if (ofil != 0)
                    (*ofil) << "about to call swap!"
                            << " ix: " << ix << " jx: " << jx << '\t'
                            << " swaping: " << vec[ix]
                            << " with " << vec[jx] << endl;

                swap(vec[ix], vec[jx]);
            }
}   


